﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kira.Compiler.Bods
{
    [XmlElementMapping("DIExcelSource")]
    public class DIExcelSource : BodsTransform
    {
        public String Name
        {
            get
            {
                return this.GetAttrbuteValue("name");
            }
        }
        public String DatastoreName
        {
            get
            {
                return this.GetAttrbuteValue("datastoreName");
            }
        }
        public String OutputName
        {
            get
            {
                return this.GetElement("DIOutputView").GetAttrbuteValue("name");
            }
        }
        public override IEnumerable<string> InputNames
        {
            get { return new String[] { }; }
        }

        public override IEnumerable<string> OutputNames
        {
            get { return new String[] { this.OutputName }; }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(GetComments("DIExcelSource"));
            sb.Append("WITH ").Append(OutputName).Append(" AS (SELECT * FROM OPENROWSET(EXCEL,'").Append(Name).AppendLine("'))");
            return sb.ToString();
        }
    }
}
